/*
    平衡二叉树：空树，或根结点左右子树高度差<=1,且左右子树也为平衡二叉树。
    判断是否是平衡二叉树
*/

function isBalance(treeNode){
    return depth(treeNode) != -1
}

function depth(node){
    if(!node) return 0
    const left = depth(node.left)
    if(left == -1) return -1
    const right = depth(node.right)
    if(right == -1) return -1
    return Math.abs(left-right) >1 ? -1 : Math.max(left, right) +1
}

const treeA = {
    left: {right:{}}
}
console.log(isBalance(treeA))

const treeB = {
    left: {right:{}},
    right:{},
}
console.log(isBalance(treeB))